package com.acyouzi.leetcode.tree;


import java.util.ArrayList;
import java.util.List;

/**
 * 17/9/13 19:49
 *
 * @author sunxu
 */

public class SecondMinimum {
  public int findSecondMinimumValue(TreeNode root) {
    List<Integer> list = new ArrayList<>();
    helper(list,root);
    return list.size() < 2 ? -1 : list.get(2);
  }

  public void helper( List<Integer> list, TreeNode node){
    if (node == null) return;
    helper(list,node.left);
    if (list.size()!=0 && list.get(list.size()-1) != node.val)list.add(node.val);
    else if (list.size() == 0) list.add(node.val);
    helper(list,node.right);
  }
}
